#!/bin/bash

########## Edit constants after this line ######################################

# Source directory. Directory where working copy of Kotoba pleaced.
SRC_DIR="/tmp/kotoba"

# Destination directory. Directory where Kotoba actually work.
ABS_PATH="/var/www/html/kotoba"

# Path from server document root to kotoba directory.
DIR_PATH="/kotoba"

# Mysql user name.
DB_USER="root"

# Mysql password. Empty string means no password.
DB_PASS=""

# Kotoba database name.
DB_BASENAME="kotoba"

# Debug installation script.
DEBUG=0

# Set this value to 1
CONFIRM_CHANGES=0

########## Do not edit code after this line ####################################

if [ $CONFIRM_CHANGES -ne 1 ]; then
    echo "Edit constants in this file first. And then start again."
    exit 1
fi

################################################################################
# Constants
#

RESOURCE_DIR="res"

################################################################################
# Functions
#

. $SRC_DIR/$RESOURCE_DIR/functions.sh

################################################################################
#
#

#
# 1. Update stored procs.
#
echo "Update stored procs."
execute "mysql -u $DB_USER `if ! [ -z "$DB_PASS" ]; then echo "-p $DB_PASS "; fi`-D $DB_BASENAME < $SRC_DIR/$RESOURCE_DIR/create_procedures.sql" "`basename $0`:$LINENO"

#
# 2. Patch database.
#
echo "Patch database."
execute "mysql -u $DB_USER `if ! [ -z "$DB_PASS" ]; then echo "-p $DB_PASS "; fi`-D $DB_BASENAME < $SRC_DIR/$RESOURCE_DIR/patch_13.sql" "`basename $0`:$LINENO"

#
# 3. Epilogue.
#
echo "Update successful."

exit 0
